<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('资产信息列表')" />
    <style>
        a{
            margin-bottom: 3px;
        }
    </style>
   </head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input name="manageDept" type="text" id="manageDept" style="display: none"/>
                    <input name="deptId" type="text" id="deptId" style="display: none"/>
                    <div class="select-list">
                        <ul>
                            <li>
                                <input type="text"  name="searchParam" placeholder="序号/编号/资产编码/名称/型号"/>
                            </li>
                            <li>
                                <input name="manageDeptName" onclick="selectDeptTree()" id="manageDeptName" type="text" placeholder="请选择管理部门">
                            </li>
                            <li>
                                <input name="deptName" onclick="selectDeptTreeUse()" id="deptName" type="text" placeholder="请选择使用部门">
                            </li>
                            <li>
                                <select name="status" class="form-control" th:with="type=${@dict.getType('status')}">
                                    <option value="">资产状态</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <!--<li>-->
                                <!--<select name="inventoryStatus" class="form-control">-->
                                    <!--<option value="">盘点情况</option>-->
                                    <!--<option value="0">未盘点</option>-->
                                    <!--<option value="1">已盘点</option>-->
                                    <!--<option value="2">盘点一次以上</option>-->
                                <!--</select>-->
                            <!--</li>-->
                            <li>
                                <select name="agreementStatus">
                                    <option value="">是否相符</option>
                                    <option value="2">第一次未盘点</option>
                                    <option value="1">是</option>
                                    <option value="0">否</option>
                                </select>
                            </li>
                            <li>
                                <select name="useStatus" class="form-control" th:with="type=${@dict.getType('consume_type')}">
                                    <option value="">消耗类型</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li class="select-time">
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="beginDate"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="endDate"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="asset:assetDetail:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-info" onclick="$.table.importExcel()" shiro:hasPermission="asset:assetDetail:import">
                    <i class="fa fa-upload"></i> 导入
                </a>
                <!--<a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="asset:assetDetail:edit">-->
                    <!--<i class="fa fa-edit"></i> 修改-->
                <!--</a>-->
                <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="asset:assetDetail:remove">-->
                    <!--<i class="fa fa-remove"></i> 删除-->
                <!--</a>-->
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="asset:assetDetail:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('asset:assetDetail:edit')}]];
        var addFlag = [[${@permission.hasPermi('asset:assetDetail:add')}]];
        var removeFlag = [[${@permission.hasPermi('asset:assetDetail:remove')}]];
        var uFlag = [[${@permission.hasPermi('asset:assetDetail:updatePrint')}]];
        var prefix = ctx + "asset/assetDetail";
        var sUserAgent = navigator.userAgent.toLowerCase();
        var bIsIpad = sUserAgent.match(/ipad/i) == 'ipad';
        var bIsIphone = sUserAgent.match(/iphone os/i) == 'iphone os';
        var bIsMidp = sUserAgent.match(/midp/i) == 'midp';
        var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == 'rv:1.2.3.4';
        var bIsUc = sUserAgent.match(/ucweb/i) == 'web';
        var bIsCE = sUserAgent.match(/windows ce/i) == 'windows ce';
        var bIsWM = sUserAgent.match(/windows mobile/i) == 'windows mobile';
        var bIsAndroid = sUserAgent.match(/android/i) == 'android';
        var isNotPc;
        if(bIsIpad || bIsIphone || bIsMidp || bIsUc7 || bIsUc || bIsCE || bIsWM || bIsAndroid ){
            isNotPc = true
            $("#toolbar").hide();
        }else{
            isNotPc = false
        }
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                importTemplateUrl: prefix + "/importTemplate",
                importUrl: prefix + "/importData",
                exportUrl: prefix + "/export",
                sortName: "icount,updateTime",
                sortOrder: "desc",
                modalName: "资产信息",
                rowStyle: rowStyle,
                height:570,
                columns: [{
                    field:'id',
                    title : '序号',
                    // formatter: function(value, row, index) {
                    //     var actions = [];
                    //     actions.push( ("0000000000000000" + row.id ).substr( -10 ));
                    //     return actions.join('');
                    // },
                    sortable:true,
                },
                    {
                        field : 'assetNo',
                        title : '卡片编号',
                        sortable:true
                    },
                {
                    field : 'assetCode',
                    title : '资产编码',
                    sortable:true
                },
                {
                    field : 'assetName', 
                    title : '资产名称'
                },
                {
                    title : '资产类别',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push($.table.selectDictLabel([[${@dict.getType('asset_type')}]], row.assetType));
                        return actions.join('');
                    },
                    visible:!isNotPc
                },
                {
                    field : 'specifications', 
                    title : '规格',
                    visible:!isNotPc
                },
                {
                    field : 'assetModel', 
                    title : '型号',
                    visible:!isNotPc
                },
                {
                    field : 'amount',
                    title : '数量',
                    visible:!isNotPc
                },
                {
                    field : 'manageDeptName',
                    title : '管理部门',
                },
                {
                    field : 'useDeptName',
                    title : '使用部门'
                },
                {
                    field : 'address', 
                    title : '使用地点'
                },
                {
                    title : '消耗类型',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push($.table.selectDictLabel([[${@dict.getType('consume_type')}]], row.consumeType));
                        return actions.join('');
                    },
                    visible:!isNotPc
                },
                {
                    title : '状态',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.consumeType!=2){
                            actions.push($.table.selectDictLabel([[${@dict.getType('status')}]], row.status));
                        }else{
                            if(row.status==0){
                                actions.push("审核中");
                            }else {
                                actions.push("审核通过");
                            }
                        }
                        return actions.join('');
                    },
                    visible:!isNotPc
                },
                    {
                        title : '是否相符',
                        formatter: function(value, row, index) {
                            var actions = [];
                            if(row.agreementStatus==0){
                                actions.push("否");
                            }
                            if(row.agreementStatus==1){
                                actions.push("是");
                            }
                            return actions.join('');
                        }
                    },
                {
                     align:'center',
                     title : '图片',
                     formatter: function(value, row, index) {
                         var actions = [];
                         actions.push('<a class="btn btn-info btn-xs" style="height: 30px;line-height: 25px" href="javascript:void(0)" onclick="showImg(\'' + row.id +","+true+ '\',\'' + row.imgCount + '\')">'+"&nbsp&nbsp"+row.imgCount+'&nbsp&nbsp</a>');
                         return actions.join('');
                     },
                },
                {
                    field : 'createByName',
                    title : '创建人',
                    visible:!isNotPc
                },
                {
                    field : 'createTime',
                    title : '创建时间',
                    sortable:true,
                    visible:!isNotPc
                },
                {
                    title: '操作',
                    align: 'left',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if (row.status==0||row.status==2){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + ',true,false,true\')"><i class="fa fa-edit"></i>审核</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + ',false,true,false\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }
                        if ((row.status!=0&&row.status!=2)||(row.status!=0&&(row.consumeType==2||row.consumeType==3))){
                            actions.push('<a class="btn btn-success btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + ',true,true,true\')"><i class="fa fa-edit"></i>查看</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + uFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + ',true,true,false\')"><i class="fa fa-edit"></i>资产变动</a> ');
                            if (!isNotPc){
                                actions.push('<a class="btn btn-success btn-xs ' + uFlag + '" href="javascript:void(0)" onclick="print(\'' + row.id + '\')"><i class="fa fa-edit"></i>打印</a> ');
                            }
                            actions.push('<a class="btn btn-danger btn-xs ' + uFlag + '" href="javascript:void(0)" onclick="lostScrap(\'' + row.id + '\')"><i class="fa fa-edit"></i>遗失报废</a> ');
                        }
                       if(!isNotPc){
                           if (row.status==1&&row.consumeType==1){
                               actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="sync(\'' + row.id + '\')"><i class="fa fa-edit"></i>手动匹配</a> ');
                           }
                           if (row.status==3){
                               actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="showClique(\'' + row.id + '\')"><i class="fa fa-edit"></i>匹配信息</a> ');
                           }
                       }
                        actions.push('<a class="btn btn-primary btn-xs" href="javascript:void(0)" onclick="addImg(\'' + row.id + '\')"><i class="fa"></i>添加图片</a>  ');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        function sync(id) {
            if(isNotPc) {
                $.modal.openFull('未匹配数据列表', prefix + "/syncView/" + id);
            }else {
                $.modal.open('未匹配数据列表', prefix + "/syncView/" + id);
            }
        }
        function print(id) {
            if(isNotPc) {
                $.modal.openFull('标签打印预览',prefix+"/printView/"+id);
            }else {
                $.modal.open('标签打印预览', prefix + "/printView/" + id);
            }
        }
        var width=isNotPc?'95%':'380';
        /*选择使用部门树*/
        function selectDeptTreeUse() {
            var deptId = $.common.isEmpty($("#deptId").val()) ? "100" : $("#deptId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width:width,
                url: url,
                callBack: doSubmitUse
            };
            $.modal.openOptions(options);
        }
        function doSubmitUse(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#deptId").val(body.find('#treeId').val());
                $("#deptName").val(body.find('#treeName').val());
                layer.close(index);
            }
            $("#useUser").empty();
            $.post(ctx +"system/user/getUserByDept",{deptId:$("#deptId").val()},function (data) {
                $.each(data,function (index,p) {
                    $("#useUser").append('<option value="'+p.userId+'">'+p.userName+'</option>');
                })
            });
        }
        /*选择管理部门树*/
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#manageDept").val()) ? "100" : $("#manageDept").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: width,
                url: url,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }
        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#manageDept").val(body.find('#treeId').val());
                $("#manageDeptName").val(body.find('#treeName').val());
                layer.close(index);
            }
            $("#manageUser").empty();
            $.post(ctx +"system/user/getUserByDept",{deptId:$("#manageDept").val()},function (data) {
                $.each(data,function (index,p) {
                    $("#manageUser").append('<option value="'+p.userId+'">'+p.userName+'</option>');
                })
            });
        }
        function showImg(id,imgCount) {
            if (parseInt(imgCount)>0){
                if(isNotPc) {
                    $.modal.openFull('资产图片',prefix+"/showImg/"+id);
                }else {
                    $.modal.open('资产图片', prefix + "/showImg/" + id);
                }
            }else{
                $.modal.alertWarning("没有图片");
            }
        }
        function addImg(id) {
            if(isNotPc) {
                $.modal.openFull('添加图片',prefix+"/addImg/"+id);
            }else {
                $.modal.open('添加图片', prefix + "/addImg/" + id);
            }
        }
        function showClique(id) {
            if(isNotPc) {
                $.modal.openFull('匹配信息',prefix+"/showClique/"+id);
            }else {
                $.modal.open('匹配信息', prefix + "/showClique/" + id);
            }
        }
        function rowStyle(row, index) {
            // if (row.agreementStatus==0){
            //     return {classes:'danger'}
            // }
            return {};
        }

        function lostScrap(id) {
            if(isNotPc) {
                $.modal.openFull('遗失报废',prefix+"/lostScrap/"+id);
            }else {
                $.modal.open('遗失报废', prefix + "/lostScrap/" + id);
            }
        }
    </script>
     <!-- 导入区域 -->
     <script id="importTpl" type="text/template">
         <form enctype="multipart/form-data" class="mt20 mb10">
             <div class="col-xs-offset-1">
                 <input type="file" id="file" name="file"/>
                 <div class="mt10 pt5">
                     <a onclick="$.table.importTemplate()" class="btn btn-default btn-xs"><i class="fa fa-file-excel-o"></i> 下载模板</a>
                 </div>
                 <font color="red" class="pull-left mt10">
                     提示：仅允许导入“xls”或“xlsx”格式文件！
                 </font>
             </div>
         </form>
     </script>
</body>
</html>